package com.situ.mall.controller;

import com.situ.common.util.PageResult;
import com.situ.common.util.Result;
import com.situ.mall.constant.RedisConstants;
import com.situ.mall.pojo.entity.Carousel;
import com.situ.mall.pojo.entity.Category;
import com.situ.mall.pojo.query.CarouselQuery;
import com.situ.mall.pojo.query.ProductQuery;
import com.situ.mall.pojo.vo.ProductVO;
import com.situ.mall.service.ICarouselService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/carousel")
public class CarouselController {
    @Autowired
    private ICarouselService carouselService;
    @Qualifier("redisTemplate")
    @Autowired
    private RedisTemplate redisTemplate;

    @RequestMapping("/list")
    @ResponseBody
    public PageResult list(CarouselQuery carouselQuery) {
        PageResult pageInfo = carouselService.list(carouselQuery);
        return pageInfo;
    }
    @RequestMapping("/add")
    @ResponseBody
    public Result add(Carousel carousel) {
        carouselService.add(carousel);
        redisTemplate.opsForSet().add(RedisConstants.UPLOAD_IMAGE_TO_DB, carousel.getImage());
        return Result.ok("添加成功");
    }
    @RequestMapping("/update")
    @ResponseBody
    public Result update(Carousel carousel) {

        carouselService.update(carousel);
        redisTemplate.opsForSet().add(RedisConstants.UPLOAD_IMAGE_TO_DB, carousel.getImage());
        return Result.ok("修改成功");
    }
    @RequestMapping("/selectById")
    @ResponseBody
    public Result selectById(Integer id) {
        Carousel carousel = carouselService.selectById(id);
        return Result.ok(carousel);
    }
    @RequestMapping("/updateStatus")
    @ResponseBody
    public Result updateStatus(Carousel carousel) {
        carouselService.update(carousel);
        return Result.ok("修改成功");
    }
    @RequestMapping("/updateIsDeleted")
    @ResponseBody
    public Result updateIsDeleted(Carousel carousel) {
        carouselService.update(carousel);
        return Result.ok("修改成功");
    }
    @RequestMapping("/deleteById")
    @ResponseBody
    public Result deleteById(Integer id) {
        carouselService.deleteById(id);
        return Result.ok("删除成功！");
    }
    @RequestMapping("/deleteAll")
    @ResponseBody
    public Result deleteAll(Integer[] ids) {
        carouselService.deleteAll(ids);
        return Result.ok("删除成功！");
    }
}
